package jphysics;

import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

/**
 * @author KaLeonis
 */
public class DCircle extends Group {
	
	private Circle c0;
	private Circle c1;
	
	public DCircle() {
		
		c0 = new Circle(400, 100, 20);
		c1 = new Circle(c0.getCenterX() + c0.getRadius(), c0.getCenterY(), 5);
		
		c0.setFill(Color.MAROON);
		c1.setFill(Color.BLACK);
		
		c0.setOnMouseDragged(new EventHandler<MouseEvent>() {
			public void handle(MouseEvent t) {
				circle_onMouseDragged(t);
			}
		});
		
		c1.setOnMouseDragged(new EventHandler<MouseEvent>() {
			public void handle(MouseEvent t) {
				c1_onMouseDragged(t);
			}
		});
		
		getChildren().add(c0);
		getChildren().add(c1);
	}
	
	private void circle_onMouseDragged(MouseEvent t) {
		c0.setCenterX(t.getX());
		c0.setCenterY(t.getY());
		c1.setCenterX(c0.getCenterX() + c0.getRadius());
		c1.setCenterY(c0.getCenterY());
	}

	private void c1_onMouseDragged(MouseEvent t) {
		c1.setCenterX(t.getX());
		c0.setRadius(c1.getCenterX() - c0.getCenterX());
	}
}
